package main;

import main.Link.SQLLink;

import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

public class KSTableModel extends AbstractTableModel {
    private String[] columnNames = {"#", "# по смете", "Наименование работы", "Ед. изм", "Количество", "Цена за единицу", "Стоимость"};
    private ArrayList<Object[]> data = new ArrayList<Object[]>();
    Class[] types = new Class[]{
            String.class, String.class, String.class, String.class, Double.class, Double.class, Double.class
    };

    public KSTableModel (ArrayList<Object[]> data) {
        this.data = data;
    }

    @Override
    public int getColumnCount() { return 7; }

    @Override
    public int getRowCount() { return data.size(); }

    @Override
    public String getColumnName(int col) { return columnNames[col]; }

    @Override
    public Object getValueAt(int row, int col) {
        Object[] str = data.get(row);

        return str[col];
/*        switch( col )
        {
            case 0: return link.getAsk();
            case 1: return link.getAction();
            case 2: return link.getTaskShortName();
            case 3: return link.getTaskName();
            case 4: return link.getSmrNum();
            case 5: return link.getSmrName();
            case 6: return link.getSmrVol();
            case 7: return link.getFact();
            case 8: return link.getFactFull();
            case 9: return link.getPv();
            default: return "Unknown";
        }
**/
    }

    public ArrayList<Object[]> getData() { return data; }

    boolean[] canEdit = new boolean[]{false, false, false, false, false, false, false};

    @Override
    public Class getColumnClass(int columnIndex) {
        return types[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
        if (data.size() > row) {
            Object[] str = data.get(row);
            str[col] = value;

        } else {

            Object[] str = new Object[] {};
            str[col] = value;
            data.add(str);
        }
        fireTableCellUpdated(row, col);
    }
}